/*
 * Created by: 
 * Created: Thursday, February 22, 2007
 */

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Edge.Business.Domain.Application;
using Edge.Common.Web.DataUtils;
using Edge.Common.Web.DataUtils;

namespace Edge.Common.Web.Application
{
    public class ContextObjects : IContextObjects
    {

        private SessionObject<Dictionary<Type, object>> tableHolder =
            new SessionObject<Dictionary<Type, object>>("Dune.Common.Web.Application.ContextObjects.tableHolder_KEY");

        public virtual T Get<T>() where T : class
        {
            return tableHolder.Value.ContainsKey(typeof(T)) ? (T)tableHolder.Value[typeof(T)] : null;
        }

        public virtual void Set<T>(T obj) where T : class
        {
            tableHolder.Value[typeof(T)] = obj;
        }

        #region IContextObjects Members

        public ICollection GetAll()
        {
            ArrayList ret = new ArrayList();
            foreach (object o in tableHolder.Value.Values)
            {
                if (o != null)
                    ret.Add(o);
            }
            return ret;
        }

        #endregion
    }
}